﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Xk
{
    public partial class frmStudentLinqToObject : Form
    {
        public frmStudentLinqToObject()
        {
            InitializeComponent();
        }

        private IEnumerable<CStudent> CreateStudents()
        {
            return new List<CStudent>
            {
                new CStudent{StuNo="00000001",StuName="林斌",Sex="男"},
                new CStudent{StuNo="00000002",StuName="彭少帆",Sex="男"},
                new CStudent{StuNo="00000003",StuName="曾敏馨",Sex="女"},
                new CStudent{StuNo="00000004",StuName="张晶晶",Sex="女"},
                new CStudent{StuNo="00000005",StuName="曹业成",Sex="男"}
            };
        }

        private void getStudent()
        {
            listBox1.Items.Clear();
            var results = from c in CreateStudents()
                          where c.StuName.Contains(txtStuName.Text)
                          select c;
            foreach (var r in results)
            {
                listBox1.Items.Add("姓名：" + r.StuName + " 性别：" + r.Sex);
            }
        }

        private void frmStudentLinqToObject_Load(object sender, EventArgs e)
        {
            CreateStudents();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            getStudent();
        }
    }
}
